﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;
using RonYee.Models;

namespace RonYee.Service
{

    public static class HasFolders 
    {
        public static string HasFolder(string path) 
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            return path;
        }
    }

    //是否存在文件
    public static class HasFiles
    {
        public static bool HasFile(this HttpPostedFileBase file)
        {
            return (file != null && file.ContentLength > 0) ? true : false;
        }
    }

    public static class GetBooksInfo
    {
        public static int GetBooksCount(string isbn)
        {
            RongeDb db = new RongeDb();
            int count = (from b in db.InStores
                         where b.ISBN == isbn
                         select b).Count();
            return count;
        }
        public static bool HasBook(string isbn)
        {
            RongeDb db = new RongeDb();
            int count = (from b in db.Books
                         where b.ISBN == isbn
                         select b).Count();
            if (count > 0)
                return true;
            else
                return false;

        }
        public static int GetBooksID(string isbn)
        {
            RongeDb db = new RongeDb();

            var id = (from b in db.Books
                      where b.ISBN == isbn
                      select b.BookId).FirstOrDefault();

            return id;
        }

    }
    public static class GetCustomerInfo
    {
        public static bool GetCustomerStatus(string name)
        {
            RongeDb db = new RongeDb();
            int status = (from c in db.Customers
                          where c.Login == name
                          select c.status).FirstOrDefault();
            if (status == 1)
                return true;
            else
                return false;
        }

    }
}
